<template>
  <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
            :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
            :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
            :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
    <!--表单开始-->
    <a-form ref="formRef" :model="formState" layout="vertical" :rules="RULES">
      <a-row :gutter="12">
        <a-col :span="12">
          <a-form-item label="发布标题" field="title">
              <a-input v-model="formState.title" allow-clear  placeholder="请输入发布标题"  :disabled="isUpdate"/>
          </a-form-item>
        </a-col>
          <a-col :span="12">
              <a-form-item label="发布分类" field="kind">
                <smart-dict v-model="formState.kind" allow-clear  :url="DictOptions.HelpKind" />
              </a-form-item>
          </a-col>
        <a-col :span="24">
          <a-form-item label="发布正文" field="body">
            <!--            <a-input v-model="formState.body" allow-clear placeholder="请输入帮助正文"/>-->
            <a-textarea v-model="formState.body" allow-clear auto-size placeholder="请输入发布的正文" />
          </a-form-item>
        </a-col>
      </a-row>

    </a-form>
    <!--表单结束-->
  </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'
import {HELP_EDIT} from "../resource/form";
import {PopHttp} from '../resource/http'
import {DictOptions} from "@/libs/options";


const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])
const { BODY ,RULES} = HELP_EDIT

const {addHelp, updateHelp} = PopHttp
const config = {tplRecord: BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addHelp).setUpdateRequest(updateHelp)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改列表' : '新建列表'
</script>
